package com.geek.novel.services

import android.content.res.Resources
import com.geek.novel.bo.AppContext
import com.geek.novel.entity.AppTypeface
import com.geek.novel.utils.GsonUtil
import com.vicpin.krealmextensions.queryAll
import com.vicpin.krealmextensions.save
import io.realm.Realm

class AppTypefaceRepository{
	
	private fun getResources(): Resources {
		return AppContext.getResources()
	}
	
	/**保存*/
	fun save(entity: AppTypeface){
		entity.save()
	}
	
	/**保存List*/
	fun saveAll(list: List<AppTypeface>){
		val jsonList = GsonUtil.toJson(list)
		val realm = Realm.getDefaultInstance()
		//开启事务，然后批量保存
		realm.executeTransaction {
			it.createOrUpdateAllFromJson(AppTypeface::class.java, jsonList)
		}
	}
	
	/**根据bookId获取数据*/
	fun findAll(): List<AppTypeface> {
		return AppTypeface().queryAll()
	}
	
}